using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Net.Fan.SmallPig.Common;

/// <summary>
/// Summary description for PageUtils
/// </summary>
public class PageUtils
{

    public static void CheckShift2SSL(Page page)
    {
        #region create and to safe connect

        if (Config.Instance.SSL && page. Request.Url.Scheme == "http")
        {
            string s = page.Request.Url.AbsoluteUri.Replace("http", "https");  //string.Format("https://{0}/{1}",Request.Url.Host,Request.Url.AbsoluteUri);
            //if use redirect will fail,becouse must make a safe connection between server and client. 
            //Response.Redirect(s, true);

            HtmlGenericControl meta = new HtmlGenericControl("meta");
            meta.Attributes.Add("HTTP-EQUIV", "REFRESH");
            meta.Attributes.Add("content", string.Format("0; URL={0}", s));
            page.Header.Controls.Add(meta);
        }

        #endregion
    }

    public static string GetParentUrl(string originalString, int decLayer)
    {
        string[] ss = originalString.Split('/');

        string tmp = string.Empty;
        for (int n = 0; n < ss.Length - decLayer; n++)
        {
            tmp += ss[n] + "/";
        }
        return tmp;
    }

}
